package com.teamin.web.scheduled;

import com.teamin.service.INetDiskService;
import com.teamin.service.impl.FileServiceImpl;
import com.teamin.service.impl.MessageServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务
 * Created by qfu on 2017/9/22.
 * 可参考 http://blog.csdn.net/ClementAD/article/details/42042111
 */
@Component
public class ScheduledJobs{
    public final static long SECOND = 1 * 1000;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${spring.profiles.active}")	//服务器环境
    String SERVICE_PROFILS ;

    @Autowired
    private FileServiceImpl fileService;
    @Autowired
    private MessageServiceImpl messageService;

    @Autowired
    private INetDiskService netDiskService;
    /**
     *  回收OSS 中上传失败的临时文件
     *  间隔2分钟,执行工单上传任务
     */
    @Scheduled(cron="0 30 3 ? * *") //每天晚上3:30 执行
    public void recoryTempFileOss() {
        if(!"test".equals(SERVICE_PROFILS)) {
            logger.info("----------开始回收临时文件");
            fileService.recoveryTempFile();
        }
    }

    /**
     *  回收OSS 中上传失败的临时文件
     *  间隔2分钟,执行工单上传任务
     */
    @Scheduled(cron="0 30 2 ? * *") //每天晚上2:30 执行
    public void recoryDeleteFileOss() {
        if(!"test".equals(SERVICE_PROFILS)) {
            logger.info("----------开始回收文件");
            fileService.recoveryDeleteFile();
            netDiskService.rmOSSFile();
        }
    }

    /**
     *  发送任务的消息
     */
    @Scheduled(cron="0 30 8 ? * *") //每天8:30 执行
    public void sendMsg() {

        if(!"test".equals(SERVICE_PROFILS)) {
            logger.info("----------发送消息");
            messageService.SendUserTaskState();
        }
    }
}
